<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="学生姓名">
              <a-input placeholder="请输入学生姓名" v-model="queryParam.professorName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
<!--    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('专家信息录入')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>-->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <span slot="professorName" slot-scope="text,record">
        <a :class="record.isLeave === 0 ? 'fontgreen' :'fontred'" disabled>{{record.professorName}}</a>
        </span>
        <span slot="isLeave" slot-scope="text,record">
        <a :class="record.isLeave === 0 ? 'fontgreen' :'fontred'" disabled>{{record.isLeave === 0?'在校':'请假'}}</a>
        </span>


        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>
        <template slot="declareCategory" slot-scope="text">
          <div>{{ initDict(text) }}</div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">查看信息</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <diyProfessorInfo-modal ref="modalForm" @ok="modalFormOk"></diyProfessorInfo-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import DiyProfessorInfoModal from './modules/DiyProfessorInfoModal'
  import { loadCategoryData } from '@/api/api'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import Area from '@/components/_util/Area'
  import JCategorySelect from '@comp/jeecg/JCategorySelect'

  export default {
    name: "DiyProfessorInfoList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JCategorySelect,
      DiyProfessorInfoModal
    },
    data () {
      return {
        description: '学生请销假管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'学生姓名',
            align:"center",
            // dataIndex: 'professorName',
            scopedSlots: { customRender: 'professorName' }
          },
          {
            title:'性别',
            align:"center",
            dataIndex: 'professorSex',
            customRender:function (text) {
              return  text=="1"?"男":"女"
            }

          },
 /*         {
            title:'出生年月',
            align:"center",
            dataIndex: 'professorBirthday',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'毕业院校',
            align:"center",
            dataIndex: 'professorSchool'
          },
          {
            title:'所学专业',
            align:"center",
            // dataIndex: 'professorMajor_dictText'
            dataIndex: 'professorMajor'
          },
          {
            title:'毕业时间',
            align:"center",
            dataIndex: 'professorGraduateDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'学历',
            align:"center",
            dataIndex: 'professorEducationBackground'
          },
          {
            title:'学位',
            align:"center",
            dataIndex: 'professorDegree'
          },
          {
            title:'工作单位',
            align:"center",
            dataIndex: 'professorWorkUnit'
          },
          {
            title:'通讯地址',
            align:"center",
            dataIndex: 'professorAddress'
          },*/
          // {
          //   title:'申报类别',
          //   align:"center",
          //   dataIndex: 'professorDeclareCategory',
          //   scopedSlots: {customRender: 'declareCategory'}
          //   // 用于渲染这个单元格的数据
          //   // customRender:function (text) {
          //   //   return text declareCategory
          //   // }
          // },
          // {
          //   title:'职务',
          //   align:"center",
          //   // dataIndex: 'professorPosition_dictText'
          //   dataIndex: 'professorPosition'
          // },
          {
            title:'请假时间',
            align:"center",
            dataIndex: 'professorBeginWork',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          // {
          //   title:'技术职称',
          //   align:"center",
          //   dataIndex: 'professorTitle'
          //   // dataIndex: 'professorTitle_dictText'
          // },
/*          {
            title:'从事专业',
            align:"center",
            dataIndex: 'professorWorkMajor'
          },
          {
            title:'从事专业时间',
            align:"center",
            dataIndex: 'professorMajorDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'身份证号',
            align:"center",
            dataIndex: 'professorIdentity'
          },
          {
            title:'家庭地址',
            align:"center",
            dataIndex: 'professorHomeAddress',
            // scopedSlots: {customRender: 'pcaSlot'}
          },*/
          {
            title:'体质状况',
            align:"center",
            dataIndex: 'professorHealth'
            // dataIndex: 'professorHealth_dictText'
          },
          {
            title:'家庭电话',
            align:"center",
            dataIndex: 'professorOfficeTel'
          },
          {
            title:'手机',
            align:"center",
            dataIndex: 'professorPhone'
          },
/*          {
            title:'本人项目简介',
            align:"center",
            dataIndex: 'professorProjectIntroduce'
          },
          {
            title:'业务主管 部门',
            align:"center",
            dataIndex: 'professorLeadMsg'
          },
          {
            title:'行政审批局意见',
            align:"center",
            dataIndex: 'professorApproveMsg'
          },
          {
            title:'照片',
            align:"center",
            dataIndex: 'professorPhotoString'
          },*/
          {
            title:'是否请假',
            align:"center",
            scopedSlots: { customRender: 'isLeave' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            // fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/org/diyProfessorInfo/list",
          delete: "/org/diyProfessorInfo/delete",
          deleteBatch: "/org/diyProfessorInfo/deleteBatch",
          exportXlsUrl: "/org/diyProfessorInfo/exportXls",
          importExcelUrl: "org/diyProfessorInfo/importExcel",
        },
        dictOptions:{},
        pcaData:''
      }
    },
    created() {
      this.pcaData = new Area()

    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDict(text){
        let textArray=[]
         textArray= text.split(",")
        let array = []
         array = this.dictOptions.professorDeclareCategory
        let dicts = ''
        // 先判断是否为空
        if(textArray.length!=null && array.length!=null){
          for (let i = 0; i < textArray.length; i++) {
            for (let j = 0; j < array.length; j++) {
              if (textArray[i] == array[j].value){
                dicts += array[j].text
                break
              }
            }
            if(i<textArray.length-1){
              dicts += "，"
            }
          }
        }


        return dicts
      },
/*      getPcaText(code){

        return this.pcaData.getText(code);
      },*/
      initDictConfig(){

        loadCategoryData({code:'B03'}).then((res) => {
          if (res.success) {
            // 把专家类型的值传入到dictOptions中
            this.$set(this.dictOptions, 'professorDeclareCategory', res.result)
            console.log("======")
            console.log(this.dictOptions)
          }
        })
      }
    }
  }
</script>
<style scoped>
  .fontgreen{
    color:green;
  }
  .fontyellow{
    color:gold;
  }
  .fontred{
    color:red;
  }
  @import '~@assets/less/common.less';
</style>